package com.shop.shop_end.utils.result;

public class ResultUtil {
    /**
     * 返回通用成功
     *
     * @param data
     * @return Result
     */
    public static Result ok(String desc, Object data) {
        Result result = new Result();
        result.setDesc(desc);
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setData(data);
        return result;
    }

    /**
     * 返回通用成功
     *
     * @param data
     * @return Result
     */
    public static Result ok(Object data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setData(data);
        return result;
    }

    /**
     * 返回通用成功
     *
     * @return Result
     */
    public static Result ok() {
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        return result;
    }

    /**
     * 返回通用错误，未知错误
     *
     * @param desc
     * @return Result
     */
    public static Result service_error(ResultCodeEnum resultCodeEnum, String desc) {
        Result result = new Result();
        result.setCode(resultCodeEnum);
        result.setDesc(desc);
        return result;
    }

    /**
     * 返回通用错误，未知错误
     *
     * @param data
     * @param desc
     * @return Result
     */
    public static Result error(String desc, Object data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.UNKNOWN_ERROR);
        result.setDesc(desc);
        result.setData(data);
        return result;
    }

    /**
     * 返回通用错误，未知错误
     *
     * @param desc
     * @return Result
     */
    public static Result error(String desc) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.UNKNOWN_ERROR);
        result.setDesc(desc);
        return result;
    }

    /**
     * 返回通用失败，失败
     *
     * @param data
     * @param desc
     * @return Result
     */
    public static Result fail(String desc, Object data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAILURE);
        result.setDesc(desc);
        result.setData(data);
        return result;
    }

    /**
     * @param desc
     * @return
     */
    public static Result fail(String desc) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAILURE);
        result.setDesc(desc);
        return result;
    }

    public static Result token_error() {
        Result result = new Result();
        result.setCode(ResultCodeEnum.LOGIN_TOKEN_ERROR).setDesc("请先登录");
        return result;
    }
}
